package com.ls.blog.config;

import lombok.Data;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: myblog
 * @author: lishun
 * @create: 2021-07-19 11:16
 **/
@Configuration
@ConfigurationProperties(prefix = "elasticsearch")
@Data
public class ElasticSearchConfig {
    private String host;
    private int port;


    @Bean
    public RestHighLevelClient client(){
        // 创建es客户端对象
        RestHighLevelClient client  = new RestHighLevelClient(RestClient.builder(
                new HttpHost(host,port)
        ));
         return client;
    }
}
